﻿using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Drawing;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;

public partial class Admin_Admin_CityArea : Admin, IRequiresSessionState
{
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.IsPostBack)
        {
            this.AdminGroup();
            this.AllCityBind();
            this.ViewState["Province"] = "";
            this.ViewState["City"] = "";
            this.ViewState["Flag"] = "";
        }
    }
    protected void AdminGroup()
    {
        if (!base.admin.CheckAdminPower(144))
        {
            base.WriteRightErrMsg();
        }
        if (!base.admin.CheckAdminPower(145))
        {
            this.Button_Add.Visible = false;
        }
        if (!base.admin.CheckAdminPower(146))
        {
            this.Button_Delete.Visible = false;
        }
        if (!base.admin.CheckAdminPower(147))
        {
            this.Button_Check_Open.Visible = false;
            this.Button_Check_Close.Visible = false;
        }
    }
    protected void AllCityBind()
    {
        this.GridView_CityArea.DataSource = Shop_City.instance.GetAllCity();
        this.GridView_CityArea.DataBind();
        this.DropDownList_Province.DataSource = Shop_City.instance.GetAllProvince();
        this.DropDownList_Province.DataBind();
        this.DropDownList_Province.Items.Insert(0, new ListItem("－请选择－", ""));
        this.DropDownList_City.Items.Insert(0, new ListItem("－请选择－", ""));
    }
    protected void InitPage(string Province, string City, int Flag)
    {
        Shop_City shop_City = new Shop_City();
        this.GridView_CityArea.DataSource = shop_City.GetCityByWhere(Province, City, Flag);
        this.GridView_CityArea.DataBind();
        this.ViewState["Province"] = Province;
        this.ViewState["City"] = City;
        this.ViewState["Flag"] = Flag;
    }
    protected void LinkButton_Command(object sender, CommandEventArgs e)
    {
        this.ViewState["Flag"] = e.CommandName;
        this.LinkButton0.ForeColor = Color.Black;
        this.LinkButton1.ForeColor = Color.Black;
        this.Button_Check_Open.Enabled = false;
        this.Button_Check_Close.Enabled = false;
        string commandName = e.CommandName;
        if (commandName != null)
        {
            if (!(commandName == "0"))
            {
                if (commandName == "1")
                {
                    this.LinkButton1.ForeColor = Color.Red;
                    this.Button_Check_Close.Enabled = true;
                }
            }
            else
            {
                this.LinkButton0.ForeColor = Color.Red;
                this.Button_Check_Open.Enabled = true;
            }
        }
        this.InitPage(this.ViewState["Province"].ToString(), this.ViewState["City"].ToString(), Convert.ToInt32(this.ViewState["Flag"]));
    }
    protected void DropDownList_Province_SelectedIndexChanged(object sender, EventArgs e)
    {
        string selectedValue = this.DropDownList_Province.SelectedValue;
        Shop_City shop_City = new Shop_City();
        this.GridView_CityArea.DataSource = shop_City.GetCityListByProvince(selectedValue);
        this.GridView_CityArea.DataBind();
        if (selectedValue != "")
        {
            this.DropDownList_City.DataSource = shop_City.GetCityByProvince(selectedValue);
            this.DropDownList_City.DataBind();
        }
        else
        {
            this.DropDownList_City.Items.Clear();
        }
        this.DropDownList_City.Items.Insert(0, new ListItem("－请选择－", ""));
        this.ViewState["Province"] = selectedValue;
    }
    protected void DropDownList_City_SelectedIndexChanged(object sender, EventArgs e)
    {
        string province = this.ViewState["Province"].ToString();
        string selectedValue = this.DropDownList_City.SelectedValue;
        Shop_City shop_City = new Shop_City();
        this.GridView_CityArea.DataSource = shop_City.GetCityByWhere(province, selectedValue, 2);
        this.GridView_CityArea.DataBind();
        this.ViewState["City"] = selectedValue;
    }
    protected void Button_Add_Click(object sender, EventArgs e)
    {
        base.Server.Transfer("Admin_CityAreaEdit.aspx?Model=_Add");
    }
    protected void Button_All_Click(object sender, EventArgs e)
    {
        this.AllCityBind();
        this.ViewState["Province"] = "";
        this.ViewState["City"] = "";
        this.ViewState["Flag"] = "";
        this.DropDownList_City.Items.Clear();
    }
    protected void LinkButton_Edit_Command(object sender, CommandEventArgs e)
    {
        if (!base.admin.CheckAdminPower(145))
        {
            base.WriteRightErrMsg();
        }
        int num = int.Parse(e.CommandName);
        base.Server.Transfer("Admin_CityAreaEdit.aspx?Model=_Edit&&ID=" + num);
    }
    protected void LinkButton_Delete_Command(object sender, CommandEventArgs e)
    {
        if (!base.admin.CheckAdminPower(146))
        {
            base.WriteRightErrMsg();
        }
        int iD = int.Parse(e.CommandName);
        Shop_City shop_City = new Shop_City();
        shop_City.DeleteCity(iD);
        base.Response.Redirect("Admin_CityArea.aspx");
    }
    protected void Button_Delete_Click(object sender, EventArgs e)
    {
        if (base.Request["id"] != null || base.Request["id"] != string.Empty)
        {
            string str = base.Request["id"].ToString();
            string sql = "DELETE FROM [HLShop_CityArea] WHERE [ID] IN(" + str + ")";
            bool flag = this.conn.Execute(sql) >= 1;
            if (flag)
            {
                this.WriteSuccessMsg("", Language.GetAdminMsg("Common/DeleteSuccess"), "Admin_CityArea.aspx");
            }
        }
    }
    protected void Button_Check_Open_Click(object sender, EventArgs e)
    {
        if (base.Request["id"] != null && base.Request["id"] != string.Empty && base.Request["id"].ToString() != "")
        {
            string str = base.Request["id"].ToString();
            string sql = "UPDATE [HLShop_CityArea] SET [Flag] = 1 WHERE [ID] IN(" + str + ")";
            bool flag = this.conn.Execute(sql) >= 1;
            if (flag)
            {
                this.WriteSuccessMsg("", Language.GetAdminMsg("Common/CheckSuccess"), "Admin_CityArea.aspx");
            }
        }
    }
    protected void Button_Check_Close_Click(object sender, EventArgs e)
    {
        if (base.Request["id"] != null && base.Request["id"] != string.Empty && base.Request["id"].ToString() != "")
        {
            string str = base.Request["id"].ToString();
            string sql = "UPDATE [HLShop_CityArea] SET [Flag] = 0 WHERE [ID] IN(" + str + ")";
            bool flag = this.conn.Execute(sql) >= 1;
            if (flag)
            {
                this.WriteSuccessMsg("", Language.GetAdminMsg("Common/CheckSuccess"), "Admin_CityArea.aspx");
            }
        }
    }
}
